cmake_minimum_required(VERSION 3.12) # 确保使用的CMake版本支持HIP

# 设置项目名称和版本
project(cuda_dnn VERSION 1.0 LANGUAGES CXX)
#set(ENV{ASAN_OPTIONS} "protect_shadow_gap=0")
# 查找CUDA包
find_package(CUDA REQUIRED)

# 检查是否找到HIP
if(NOT CUDA_FOUND)
    message(FATAL_ERROR "CUDA is required but not found.")
endif()

### 内存泄漏检查
# export ASAN_OPTIONS=protect_shadow_gap=0 避免cuda执行
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-recover=all -fsanitize=leak -fno-omit-frame-pointer -fno-common -fsanitize-address-use-after-scope")
#set (CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fsanitize=address -fsanitize-recover=all -fsanitize=leak -fno-omit-frame-pointer -fno-common -fsanitize-address-use-after-scope")

### 设置编译模式为debug

# 设置C++编译选项以生成调试信息
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")

# 设置CUDA编译选项以生成调试信息
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -G -g")



# 添加文件
set(SRC_FILES
    src/tensor.cu
    src/math_ops.cu
    src/conv.cu
)
include_directories(
    ${CUDA_INCLUDE_DIRS}
    include
)

# 添加可执行文件
cuda_add_library(tensor_library STATIC
    ${SRC_FILES}
)

add_subdirectory(demo)
add_subdirectory(test)